Skip to content

Conversation

@rouzwelt
Copy link
Collaborator

@rouzwelt rouzwelt commented Jan 22, 2026

Motivation

Solution

Checks

By submitting this for review, I'm confirming I've done the following:

  • made this PR as small as possible
  • unit-tested any new functionality
  • linked any relevant issues or PRs
  • included screenshots (if this involves a front-end change)

Summary by CodeRabbit

  • New Features

    • V6 orderbook support: new V6 contract/address entries and V6-aware arbitration paths.
  • Updates

    • Configuration examples and runtime config accept V6 entries; order metadata now includes orderbook version.
    • Calldata/routing selection updated to pick appropriate ABI paths across V4/V5/V6.
    • Subgraph versioning added to distinguish legacy vs V6 sources and tag fetched data.
  • Tests

    • Expanded coverage for V5/V6 flows, encoding, and version-aware behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@rouzwelt rouzwelt self-assigned this Jan 22, 2026
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

Walkthrough

Adds V6 support: config/subgraph entries, new ABIs (orderbook/deployer V6), versioned subgraph handling, order/orderbook version fields, V5/V6 take-orders config and calldata paths, contract resolution for v6, and corresponding tests across simulators, routers, and state.

Changes

Cohort / File(s) Summary
Configuration & Examples
config.env.yaml, config.example.yaml
Add contracts.v6 block (sushiArbAddress, genericArbAddress, balancerArbAddress, stabullArbAddress, dispair) and v6= subgraph example.
Config Types & Validation
src/config/yaml.ts, src/config/validators.ts
Add AppOptionsContracts.v6 typing and validator logic to resolve/populate v6 addresses alongside v4/v5.
ABIs: Orderbook & Deployer
src/common/abis/orderbook.ts, src/common/abis/deployer.ts
Introduce _v6 ABI namespace and OrderbookAbi.V6 (parsed Arb/Orderbook/structs); add DeployerV6 ABI entry. Note: duplicate _v6 namespace appears in orderbook.ts.
Subgraph Versioning
src/subgraph/types.ts, src/subgraph/index.ts, src/subgraph/index.test.ts
Add SubgraphVersions enum, SubgraphVersionList, per-URL version handling (v6= prefix), getSubgraphVersion, and propagate __version on fetched orders/transactions; tests updated.
Order Types & Exports
src/order/types/index.ts, src/order/types/v3.ts, src/order/types/v4.ts, src/order/types/*test.ts
Add OrderbookVersions enum (V4,V5,V6), include orderbookVersion on Pair objects, add TakeOrdersConfigTypeV5, and split V4 guards into V4/V5/V6 variants.
Order Sync & Index Tests
src/order/sync.ts, src/order/sync.test.ts, src/order/index.test.ts
Propagate __version from upstream events into orders during sync; adjust tests/mocks to assert and use versioned orders.
State / Contracts Resolution
src/state/contracts.ts, src/state/contracts.test.ts
Add optional v6 to SolverContracts, resolveVersionContracts/fromAppOptions support for v6, and getAddressesForTrade branch for V6; tests extended for v6 flows.
Inter-Orderbook Simulator
src/core/modes/inter/simulate.ts, src/core/modes/inter/simulate.test.ts
Add TakeOrdersConfigTypeV5, getTakeOrdersConfigV5, getEncodedCounterpartyTakeOrdersConfigV5; route take-orders config and counterparty encoding to V3/V4/V5; support arb5 (V6) calldata.
Router Simulator & Types
src/core/modes/router/simulate.ts, src/core/modes/router/simulate.test.ts, src/router/types.ts, src/router/types.test.ts
Router calldata selection adds V6 branch (arb5) for V6-enabled orderbooks; add getTakeOrdersConfigV5 in router types and update tests for V3/V4/V5/V6.
Integration & Router Tests
src/router/*/index.test.ts, src/router/types.test.ts
Update router integration tests to include orderbookVersion in mocks and add runtime assertions for TakeOrdersConfigType variants.
Misc: Tests & Libraries
lib/sushiswap, package.json
Updated sushiswap submodule pointer; various test imports adjusted to expose new enums/types.

Sequence Diagram(s)

sequenceDiagram
  participant Subgraph as SubgraphManager
  participant Sync as OrderSync
  participant Order as OrderManager
  participant Router as Router/Simulator
  participant Contracts as SolverContracts
  participant Chain as Onchain/ABI

  Subgraph->>Sync: fetchAll(urls) with per-URL version
  Note right of Subgraph: results annotated with __version
  Sync->>Order: iterEvents yields events + version
  Order->>Order: attach event.order.__version
  Order->>Router: build Pair (includes orderbookVersion)
  Router->>Contracts: getAddressesForTrade(orderbookVersion)
  Router->>Router: select getTakeOrdersConfigV3|V4|V5 (branch by orderbookVersion)
  Router->>Chain: encode calldata using selected ABI (arb3|arb4|arb5)
  Chain-->>Router: calldata
  Router-->>Order: return encoded calldata/result
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • rainlanguage/rain.solver#399: Overlaps ABI module changes (orderbook/deployer) and earlier versioned ABI work that this PR extends to v6.
  • rainlanguage/rain.solver#396: Related router/simulator logic changes; previously adjusted calldata/ABI selection paths that this PR further extends.
  • rainlanguage/rain.solver#400: Prior work on versioned contracts/orderbook infrastructure that this PR builds upon for v6 support.

Suggested labels

new feature, enhancement

Suggested reviewers

  • hardyjosh
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 61.54% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'v6 orderbook' is concise and directly identifies the main feature being added across the entire changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/core/modes/router/simulate.ts (1)

62-62: Update documentation to reflect V6 support.

The comment states the simulator "supports both V4 and V5 orderbook (order v3 and v4) types" but the implementation now also includes V6 orderbook support.

📝 Suggested documentation update
- * The simulator supports both V4 and V5 orderbook (order v3 and v4) types.
+ * The simulator supports V4, V5, and V6 orderbook (order v3 and v4) types.
src/subgraph/index.ts (1)

146-165: Consider defaulting version inside fetchSubgraphOrders.
Since the version is derived from the URL anyway, allowing the method to resolve it when omitted reduces the chance of mismatched tagging by external callers.

♻️ Suggested adjustment
-    async fetchSubgraphOrders(url: string, version: SubgraphVersions): Promise<SgOrder[]> {
+    async fetchSubgraphOrders(url: string, version?: SubgraphVersions): Promise<SgOrder[]> {
         const result: SgOrder[] = [];
         let skip = 0;
         let timestamp = Date.now();
         for (;;) {
             timestamp = Date.now();
             const res = await axios.post(
                 url,
                 {
                     query: getQueryPaginated(skip, this.filters),
                 },
                 { headers, timeout: this.requestTimeout },
             );
             if (res?.data?.data?.orders) {
                 const orders: SgOrder[] = res.data.data.orders;
-                if (version === SubgraphVersions.V6) {
+                const resolvedVersion = version ?? this.getSubgraphVersion(url);
+                if (resolvedVersion === SubgraphVersions.V6) {
                     orders.forEach((v) => (v.__version = SubgraphVersions.V6));
                 } else {
                     orders.forEach((v) => (v.__version = SubgraphVersions.OLD_V));
                 }
🤖 Fix all issues with AI agents
In `@src/common/abis/orderbook.ts`:
- Around line 103-154: The TakeOrdersConfigV5 ABI struct fields in namespace _v6
(symbol TakeOrdersConfigV5) don't match the TypeScript type
(TakeOrdersConfigTypeV5) — update the ABI string for TakeOrdersConfigV5 to use
minimumIO, maximumIO, maximumIORatio, add the bool IOIsInput field, then orders
and data (i.e. `(${Float} minimumIO, ${Float} maximumIO, ${Float}
maximumIORatio, bool IOIsInput, ${TakeOrderConfigV4}[] orders, bytes data)`) so
calldata encoding for takeOrders4 and arb5 will align with the TypeScript types.

In `@src/core/modes/inter/simulate.test.ts`:
- Around line 638-691: The test description is wrong: update the it(...)
description that currently reads "should return v4 config" to accurately say
"should return v5 config" (the test is exercising getTakeOrdersConfigV5 and
asserting V5-specific fields like minimumIO, maximumIO, maximumIORatio,
IOIsInput), i.e., locate the it block with the string literal "should return v4
config" and change it to reference V5 so the test name matches the behavior
being tested.

In `@src/core/modes/inter/simulate.ts`:
- Around line 323-350: The method getTakeOrdersConfigV5 currently has a
docstring mentioning "V4" which is incorrect; update the comment to describe V5
semantics and parameters: change the header to reference TakeOrdersConfigTypeV5
and V5 order/counterparty parameters, and adjust any parameter descriptions
(orderDetails: PairV4 -> V5-specific wording, counterpartyOrderDetails: Pair) to
reflect this method builds a V5 take-orders config including encodedFN; ensure
the summary, param descriptions, and return type mention V5
(TakeOrdersConfigTypeV5) and that data is ABI-encoded with orderbook and
encodedFN.

In `@src/order/sync.ts`:
- Around line 18-19: The yield currently sets version: res.__version
unconditionally which can overwrite an existing event.order.__version; change
the assignment to guard against undefined by using res.__version when it's
defined, otherwise fall back to the existing event.order.__version (e.g.
version: res.__version !== undefined ? res.__version : event?.order?.__version).
Update both occurrences where the yield/object uses version (the one with yield
{ event, url, timestamp: Number(res.timestamp), version: res.__version } and the
similar occurrence around lines 79-80) so you only overwrite when the upstream
provides a __version.

In `@src/order/types/v4.ts`:
- Around line 85-93: The comment above TakeOrdersConfigTypeV5 is misleading
because it says "version 6 orderbook" while the type name indicates this is the
V5 config shape; update the comment or name so they align — e.g., change the
comment to "Represents the V5 take orders configuration used by the version 6
orderbook (config schema v5)" or rename TakeOrdersConfigTypeV5 to
TakeOrdersConfigTypeV6 if the intent is a V6 config; adjust any references to
the type accordingly.

In `@src/router/types.ts`:
- Around line 235-244: The JSDoc incorrectly states "Creates a new
TakeOrdersConfigTypeV4" while the implementation constructs
TakeOrdersConfigTypeV5; update the documentation to reference
TakeOrdersConfigTypeV5 (and any other V4 mentions) so it matches the produced
type. Locate the JSDoc block documenting the method that returns
TakeOrdersConfigTypeV5 and replace "V4" with "V5", and adjust any param text if
it still incorrectly refers to v4 order objects to accurately say v5 where
applicable.

In `@src/subgraph/types.ts`:
- Around line 103-106: The enum member OLD_V in SubgraphVersions is ambiguous;
rename OLD_V to a clearer identifier such as LEGACY or PRE_V6 in the
SubgraphVersions enum declaration and update all references/usages of
SubgraphVersions.OLD_V across the codebase (imports, switch cases, comparisons,
and tests) to the new name to preserve behavior and ensure type safety.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/state/contracts.ts (2)

72-101: Consider extracting version-specific configuration to reduce duplication.

The resolveVersionContracts function now has repeated conditional checks for version === "v6". While functional, this could become harder to maintain as more versions are added.

Consider a lookup-based approach:

♻️ Suggested refactor for version configuration
const VERSION_CONFIG = {
    v4: { interpreterFn: "iInterpreter", storeFn: "iStore", abi: ABI.Deployer.Primary.Deployer },
    v5: { interpreterFn: "iInterpreter", storeFn: "iStore", abi: ABI.Deployer.Primary.Deployer },
    v6: { interpreterFn: "I_INTERPRETER", storeFn: "I_STORE", abi: ABI.Deployer.Primary.DeployerV6 },
} as const;

// Then use:
const config = VERSION_CONFIG[version ?? "v4"];
const interpreter = await client.readContract({
    address: addresses.dispair,
    functionName: config.interpreterFn,
    abi: config.abi,
}).catch(() => undefined);

103-109: Consider using a typed result instead of any.

Using any for the result object bypasses TypeScript's type checking. A more type-safe approach would be to explicitly type the result.

🛡️ Suggested fix for type safety
-    const result: any = {
+    const result: NonNullable<SolverContracts["v4" | "v5" | "v6"]> = {
         dispair: {
             deployer: addresses.dispair,
-            interpreter,
-            store,
+            interpreter: interpreter as `0x${string}`,
+            store: store as `0x${string}`,
         },
     };
🤖 Fix all issues with AI agents
In `@src/common/abis/orderbook.ts`:
- Around line 149-154: Remove or document the commented-out arb4 signature
inside the exported Arb constant: either delete the commented line referencing
`arb4(address orderBook, ${TakeOrdersConfigV5} calldata startTakeOrders,
${TakeOrdersConfigV5} calldata endTakeOrders, bytes calldata exchangeData,
${TaskV2} calldata task) external payable` to eliminate dead code, or replace it
with a brief TODO noting planned implementation and rationale (e.g., "TODO:
implement arb4 for v4 routing support — keep signature for future use") so
readers know why it remains; update the surrounding `Arb` export accordingly
(symbols: Arb, arb4, arb5, TakeOrdersConfigV5, TaskV2).
- Around line 249-260: Update the incorrect JSDoc references inside the V6
namespace to say "v6" where appropriate: change the comment for
Primary.Orderbook (currently "Orderbook v4 contract ABI") to "Orderbook v6
contract ABI", change any mentions like "Orderbook v4 structs" to "Orderbook v6
structs", and update the summary line that reads "Orderbook v4 and Arb
contracts" to "Orderbook v6 and Arb contracts"; keep the OrderStructAbi JSDoc
referencing OrderV4 unchanged since the struct name is OrderV4. Ensure you
modify comments near the V6 namespace and the Primary exports (Arb, Orderbook,
OrderStructAbi) so all JSDoc text consistently reflects v6.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@config.example.yaml`:
- Around line 35-40: Update the comment above the subgraph list (the lines
describing v6 behavior) to correct "thats" to "that's" and rephrase for clarity:
state that because the v5 and v6 subgraphs use the same schema/format, you must
prefix a v6 URL with "v6=" to explicitly mark it as v6; keep the example entry
"- v6=https://v6-subgraph.com" and ensure the comment mentions the need for the
"v6=" prefix to distinguish v6 despite identical schemas.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/subgraph/index.ts (1)

58-63: Avoid returning values from forEach callbacks (Biome error).
Biome flags these callbacks because the assignment expression returns a value. Use block bodies (or a simple for...of) to keep callbacks void.

🧹 Suggested fixes
-        this.subgraphs.forEach(
-            (url) =>
-                (this.syncState[url] = {
-                    skip: 0,
-                    lastFetchTimestamp: 0,
-                }),
-        );
+        this.subgraphs.forEach((url) => {
+            this.syncState[url] = {
+                skip: 0,
+                lastFetchTimestamp: 0,
+            };
+        });
-                if (version === SubgraphVersions.V6) {
-                    orders.forEach((v) => (v.__version = SubgraphVersions.V6));
-                } else {
-                    orders.forEach((v) => (v.__version = SubgraphVersions.LEGACY));
-                }
+                const tag =
+                    version === SubgraphVersions.V6 ? SubgraphVersions.V6 : SubgraphVersions.LEGACY;
+                orders.forEach((v) => {
+                    v.__version = tag;
+                });
-                        if (this.getSubgraphVersion(url) === SubgraphVersions.V6) {
-                            txs.forEach((v) => (v.__version = SubgraphVersions.V6));
-                        } else {
-                            txs.forEach((v) => (v.__version = SubgraphVersions.LEGACY));
-                        }
+                        const tag =
+                            this.getSubgraphVersion(url) === SubgraphVersions.V6
+                                ? SubgraphVersions.V6
+                                : SubgraphVersions.LEGACY;
+                        txs.forEach((v) => {
+                            v.__version = tag;
+                        });

Also applies to: 146-166, 242-248

🤖 Fix all issues with AI agents
In `@src/subgraph/index.ts`:
- Around line 19-23: The top-line comment above the SubgraphVersionList type
contains a typo ("subgraoh"); update the comment to read something like "keeps
track of subgraph versions" (or a grammatically complete sentence) so the
comment for the exported type SubgraphVersionList accurately spells "subgraph"
and clearly describes the type's purpose.
- Around line 276-283: getSubgraphVersion currently checks the exact URL against
this.versions.v6 and will misclassify config-style strings like "v6=..."; update
getSubgraphVersion to normalize the input by stripping any leading "v6=" prefix
(case-sensitive or optionally case-insensitive if you prefer) and then perform
the lookup against this.versions.v6, returning SubgraphVersions.V6 when found
and SubgraphVersions.LEGACY otherwise (refer to the getSubgraphVersion method
and this.versions.v6 symbol to locate the change).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants